"""
File: contacts_page.py
Author: ershixiong
Date: 2023/11/23
describe:

"""
from time import sleep

from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.wait import WebDriverWait

from project202311_wework.wework.wework_po.page_object.base_page import BasePage
from project202311_wework.wework.wework_po.utiles.log_utils import logger


class ContractsPage(BasePage):
    __ELE_ADD_MEMBER = (By.CSS_SELECTOR, '.member_colRight .ww_operationBar:nth-child(1) .js_add_member')
    __BTN_DELETE = (By.CSS_SELECTOR, '.js_delete')
    __BTN_DELETE_CONFIRM = (By.CSS_SELECTOR, '.ww_btn_Blue')

    def member_add_click(self):
        logger.info('通讯录页面，点击新增成员按钮')
        ele_add_member = self.wait_element_until_clickable(self.__ELE_ADD_MEMBER)

        ActionChains(self.driver).double_click(ele_add_member).perform()
        from project202311_wework.wework.wework_po.page_object.member_add_page import MemberAddPage
        return MemberAddPage(self.driver)

    def get_member_add_result(self, _username):
        logger.info('通讯录页面，获取新增结果')
        res = self.do_finds(By.CSS_SELECTOR, f'[title="{_username}"]')

        logger.debug(f'添加数据实际名称为：{res[0].text}，期望名称为：{_username}')
        return res[0].text

    def member_delete(self, _username):
        logger.info('通讯录页面，删除成员')
        # 点击复选框
        self.do_click(By.XPATH, f'//*[text()="{_username}"]/../..//input')

        # 清理数据
        self.do_click(*self.__BTN_DELETE)
        self.do_click(*self.__BTN_DELETE_CONFIRM)

        return ContractsPage(self.driver)

    def get_member_delete_result(self, _username):
        logger.info('通讯录页面，获取删除结果')
        res = self.do_finds(By.CSS_SELECTOR, f'[title="{_username}"]')
        return res

    def group_add_click(self):
        from project202311_wework.wework.wework_po.page_object.group_add_page import GroupAddPage
        return GroupAddPage(self.driver)

    def get_group_add_result(self):
        pass

    def group_delete(self):
        pass

    def get_group_delete_result(self):
        pass
